package com.yuanfeng.payment.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.nacos.common.utils.CollectionUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.yuanfeng.commoms.config.YFConfig;
import com.yuanfeng.commoms.constant.CommonType;
import com.yuanfeng.commoms.dto.userms.UserInfoDTO;
import com.yuanfeng.commoms.exception.BizCodeEnume;
import com.yuanfeng.commoms.util.*;
import com.yuanfeng.commoms.util.excel.ExcelsUtil;
import com.yuanfeng.commoms.util.querypage.PageUtils;
import com.yuanfeng.commoms.util.querypage.Query;
import com.yuanfeng.commoms.vo.shop.ShopUserMessageResultVO;
import com.yuanfeng.commoms.vo.user.UserInfoVO;
import com.yuanfeng.payment.dto.ConsumeWithdrawDTO;
import com.yuanfeng.payment.entity.PayConsumeRecordEntity;
import com.yuanfeng.payment.entity.PayConsumeWithdrawEntity;
import com.yuanfeng.payment.feign.BusinessServiceClient;
import com.yuanfeng.payment.mapper.*;
import com.yuanfeng.payment.service.PayConsumeWithdrawService;
import com.yuanfeng.payment.vo.OrderSettlementVO;
import com.yuanfeng.payment.vo.PageInfoVO;
import com.yuanfeng.payment.vo.ShopBankMessageVO;
import com.yuanfeng.payment.vo.WithdrawRecordVO;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import java.math.BigDecimal;
import java.util.*;

/**
 *
 */
@Service
public class PayConsumeWithdrawServiceImpl extends ServiceImpl<PayConsumeWithdrawMapper, PayConsumeWithdrawEntity>
        implements PayConsumeWithdrawService {

    @Autowired
    private BusinessServiceClient businessServiceClient;

    @Autowired
    private PayConsumeRecordMapper payConsumeRecordMapper;

    @Autowired
    private PayUserResourceMapper payUserResourceMapper;

    @Autowired
    private PayAssetDetailsMapper payAssetDetailsMapper;

    @Autowired
    private PayFxAccountMapper payFxAccountMapper;

    @Override
    public ResponseResult querySettlementOrder(Map<String, Object> map) {
        String token = (String) map.get("token");
        boolean isExistToken = RedisUtil.exists(YFConfig.YF_USER_TOKEN_USER + token);
        if (!isExistToken) {
            return ResponseResult.fail(10086, "token失效，请重新获取！");
        }
        try {
            String userInfoStr = RedisUtil.get(YFConfig.YF_USER_TOKEN_USER + token);
            UserInfoVO userInfo = ParseTokenUtils.getUserInfoByToken(token);
            String userId = userInfo.getUserId();
            // 获取商家店铺主账号用户id
            if (null != userInfo.getShopId()) {
                userId = this.baseMapper.getUserIDByShopId(userInfo.getShopId());
            }
            Integer settleType = null == map.get("settleType") ? null : (Integer) map.get("settleType");
            Page<OrderSettlementVO> page = new Page<>(Integer.parseInt(map.get("page") + ""), Integer.parseInt(map.get("limit") + ""));
            IPage<OrderSettlementVO> settlementList;
            if (null == settleType) {
                settlementList = this.baseMapper.querySettlementOrder(page, userId,null);
            } else {
                settlementList = this.baseMapper.querySettlementOrder(page, userId, settleType);
            }
            BigDecimal sumRecordMoney = this.baseMapper.getSumRecordMoney(userId,settleType);
            PageInfoVO infoVO = new PageInfoVO();
            infoVO.setPageList(PageUtils.getPage(settlementList));
            infoVO.setSumRecordMoney(sumRecordMoney);
            return ResponseResult.success(infoVO);
        } catch (Exception e) {
            return ResponseResult.fail(500, e.getMessage());
        }
    }

    @Override
    public ResponseResult queryMoney(Map<String, Object> map) {
        String token = (String) map.get("token");
        boolean isExistToken = RedisUtil.exists(YFConfig.YF_USER_TOKEN_USER + token);
        if (!isExistToken) {
            return ResponseResult.fail(10086, "token失效，请重新获取！");
        }
        try {
            String userInfoStr = RedisUtil.get(YFConfig.YF_USER_TOKEN_USER + token);
            UserInfoDTO dto = JSON.parseObject(userInfoStr, UserInfoDTO.class);
            UserInfoVO userInfo = dto.getUser();
            String userId = userInfo.getUserId();
            @SuppressWarnings("unchecked")
            List<Integer> recordIdList = (List<Integer>) map.get("recordId");
            if (recordIdList.isEmpty()) {
                // 判断为空，处理所有金额
                BigDecimal totalMoney = this.baseMapper.queryAllMoney(userId);
                return ResponseResult.success(totalMoney);
            }
            BigDecimal recordMoney = this.baseMapper.queryRecordMoney(recordIdList, userId);
            return ResponseResult.success(recordMoney);
        } catch (Exception e) {
            return ResponseResult.fail(500, e.getMessage());
        }
    }

    @Override
    @Transactional
    public ResponseResult queryWithdrawal(Map<String, Object> map) {
        String token = (String) map.get("token");
        boolean isExistToken = RedisUtil.exists(YFConfig.YF_USER_TOKEN_USER + token);
        if (!isExistToken) {
            return ResponseResult.fail(10086, "token失效，请重新获取！");
        }
        try {
            String userInfoStr = RedisUtil.get(YFConfig.YF_USER_TOKEN_USER + token);
            UserInfoDTO dto = JSON.parseObject(userInfoStr, UserInfoDTO.class);
            UserInfoVO userInfo = dto.getUser();
            // 发送人id
            String userId = userInfo.getUserId();
            String userName = userInfo.getUserName();
            Integer shopId = Integer.valueOf(userInfo.getShopId());
            // 收款方
            String payee = (String) map.get("payee");
            // 银行名称
            String bankName = (String) map.get("bankName");
            // 银行卡号
            String bankNum = (String) map.get("bankNum");
            // 支行所在地
            String bankAddress = (String) map.get("bankAddress");
            // 提现金额
            String money = (String) map.get("money");
            // 类型转换
            BigDecimal userMoney = new BigDecimal(0);
            // 判断是否是全部提现
            Integer type = (Integer) map.get("type");
            // 结算单号
            String statementNo = null;
            List<String> no = new ArrayList<String>();
            List<String> list = new ArrayList<String>();
            @SuppressWarnings("unused")
            // 提现说明
            String withdrawalInstructions = (String) map.get("withdrawalInstructions");
            // 手机验证码
            String phoneValidation = (String) map.get("phoneValidation");
            // 获取存储手机验证码
            String phoneCode = RedisUtil.get(YFConfig.YF_VERIFICODE_CLIENT_SESSION_ID + "_" + token);
            String con = "商家提现";
            // 提现订单号
            String orderId = "W" + TimeStampUtil.getTimeStamp() + TimeStampUtil.randomLengthByTwo();
            String recordDate = TimeStampUtil.getYear() + "-" + TimeStampUtil.getMonth() + "-"
                    + TimeStampUtil.getDay();
            String recordYear = TimeStampUtil.getYear();
            String recordMonth = TimeStampUtil.getMonth();
            String recordDay = TimeStampUtil.getDay();
            String recordTitle = "提现";
            String recordDesc = con;
            Integer tradeTypeId = 4;
            Integer userType = 1;
            Integer recordStatus = 8;
            // 商家用户提现，判断验证是否正确
            if (!phoneValidation.equals(phoneCode)) {
                return ResponseResult.fail(10015, "验证码错误！");
            }
            String createTime = TimeStampUtil.getNowDate();
            ShopUserMessageResultVO shopUserMessageResult = businessServiceClient.queryUserId(shopId);
            String shopName = null;
            if (shopUserMessageResult != null) {
                shopName = shopUserMessageResult.getShopName();
            }
            boolean isUpdateSuccess = false;
            if (type == 1) {
                statementNo = (String) map.get("statementNo");
                String str[] = statementNo.split(",");
                list = Arrays.asList(str);
                userMoney = this.baseMapper.queryCalculateRecordMoney(list, userId);
                // 更新结算单表
                isUpdateSuccess = this.baseMapper.updateRecordWithdraw(list);
            } else {
                // 查询所有结算单
                no = this.baseMapper.queryAllStatementNo(userId);
                list = no;
                userMoney = this.baseMapper.queryCalculateRecordMoney(list, userId);
                // 更新结算单表
                isUpdateSuccess = this.baseMapper.updateRecordWithdraw(no);
            }
            String recordPayorder = statementNo;
//            // 判断结算单金额
//            boolean checkSettlementAmount = this.baseMapper.checkSettlementAmount(shopId.toString());
//            if (checkSettlementAmount) {
//                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
//                return ResponseResult.fail(10059, "有未确认结算单，请确认！");
//            }
            Integer settleType = this.baseMapper.querysettleType(statementNo);

            Map<String,Object> paraMap = new HashMap<>();
            //通用参数
            paraMap.put("userId",userId);
            paraMap.put("userName",userName);
            paraMap.put("orderId",orderId);
            paraMap.put("money",userMoney);
            //withdraw参数
            paraMap.put("createTime",createTime);
            paraMap.put("con",con);
            paraMap.put("bankName",bankName);
            paraMap.put("bankAddress",bankAddress);
            paraMap.put("bankNum",bankNum);
            paraMap.put("payee",payee);
            paraMap.put("statementNo",statementNo);
            paraMap.put("shopName",shopName);
            paraMap.put("settleType",settleType);
            //record参数
            paraMap.put("recordDate",recordDate);
            paraMap.put("recordYear",recordYear);
            paraMap.put("recordMonth",recordMonth);
            paraMap.put("recordDay",recordDay);
            paraMap.put("recordTitle",recordTitle);
            paraMap.put("recordDesc",recordDesc);
            paraMap.put("tradeTypeId",tradeTypeId);
            paraMap.put("userType",userType);
            paraMap.put("recordStatus",recordStatus);
            paraMap.put("recordPayorder",recordPayorder);
            // 插入withdraw表记录
            boolean isInsertSuccess = this.baseMapper.insertConsumeWithdrawBySeller(paraMap);
            // 插入record提现明细
            boolean isInsertRecordSuccess = this.baseMapper.insertRecord(paraMap);
            if (!(isInsertSuccess && isUpdateSuccess && isInsertRecordSuccess)) {
                return ResponseResult.fail(2, "提现申请提交失败！");
            }
            //更新我的余额明细
            Map<String, Object> assetDetailMap = new HashMap<>();
            assetDetailMap.put("assetDirection", "提现");
            assetDetailMap.put("detailType", 4);
            assetDetailMap.put("assetType", 2);
            assetDetailMap.put("payType", 1);
            assetDetailMap.put("assetAmount", money);
            assetDetailMap.put("userId", userId);
            assetDetailMap.put("orderId", orderId);
            this.baseMapper.insertDetail(assetDetailMap);
            return ResponseResult.success(1, "提现申请已提交，等待审核中！");
        } catch (Exception e) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return ResponseResult.fail(500, e.getMessage());
        }
    }

    @Override
    public ResponseResult queryUserInfo(Map<String, Object> map) {
        String token = (String) map.get("token");
        boolean isExistToken = RedisUtil.exists(YFConfig.YF_USER_TOKEN_USER + token);
        if (!isExistToken) {
            return ResponseResult.fail(10086, "token失效，请重新获取！");
        }
        try {
            String userInfoStr = RedisUtil.get(YFConfig.YF_USER_TOKEN_USER + token);
            UserInfoDTO dto = JSON.parseObject(userInfoStr, UserInfoDTO.class);
            UserInfoVO userInfo = dto.getUser();
            ShopBankMessageVO sbmr = this.baseMapper.getShopBankMessage(userInfo.getShopId());
            return ResponseResult.success(sbmr);
        } catch (Exception e) {
            return ResponseResult.fail(500, e.getMessage());
        }
    }

    @Override
    public ResponseResult queryBusiness(Map<String, Object> map) {
        String token = (String) map.get("token");
        boolean isExistToken = RedisUtil.exists(YFConfig.YF_USER_TOKEN_USER + token);
        if (!isExistToken) {
            return ResponseResult.fail(10086, "token失效，请重新获取！");
        }
        try {
            String userInfoStr = RedisUtil.get(YFConfig.YF_USER_TOKEN_USER + token);
            UserInfoVO userInfo = ParseTokenUtils.getUserInfoByToken(token);
            String userId = userInfo.getUserId();
            // 获取商家店铺主账号用户id
            if (null != userInfo.getShopId()) {
                userId = this.baseMapper.getUserIDByShopId(userInfo.getShopId());
            }
            Integer type = (Integer) map.get("type");
            String allStatus = null;
            Integer otherStatus = null;
            if (type == 1) {
                // 查看全部
                allStatus = "''";
            } else if (type == 2) {
                // 待审核
                otherStatus = 0;
            } else if (type == 3) {
                // 通过
                otherStatus = 3;
            } else if (type == 4) {
                // 打款完成
                otherStatus = 2;
            } else if (type == 5) {
                // 不通过
                otherStatus = 4;
            } else if (type == 6) {
                // 进行中
                otherStatus = 1;
            }
            map.put("allStatus", allStatus);
            map.put("otherStatus", otherStatus);
            map.put("userId", userId);
            Page<WithdrawRecordVO> page = new Page<>(Integer.parseInt(map.get("page") + ""), Integer.parseInt(map.get("limit") + ""));
            IPage<WithdrawRecordVO> withdrawMessageList = this.baseMapper.queryWithdrawRecord(page, map);
            BigDecimal sumAmount = BigDecimal.ZERO;
            BigDecimal sumPayAmount = BigDecimal.ZERO;
            for (WithdrawRecordVO list : withdrawMessageList.getRecords()) {
                sumAmount = sumAmount.add(list.getAmount());
                sumPayAmount = sumPayAmount.add(null == list.getPayAmount() ? BigDecimal.ZERO : list.getPayAmount());
            }
            PageInfoVO infoVO = new PageInfoVO();
            infoVO.setPageList(PageUtils.getPage(withdrawMessageList));
            infoVO.setSumAmount(sumAmount);
            infoVO.setSumPayAmount(sumPayAmount);
            return ResponseResult.success(infoVO);
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseResult.fail(500, e.getMessage());
        }
    }

    @Override
    public ResponseResult queryBusinessCheck(Map<String, Object> map) {
        String token = (String) map.get("token");
        boolean isExistToken = RedisUtil.exists(YFConfig.YF_USER_TOKEN_USER + token);
        if (!isExistToken) {
            return ResponseResult.fail(10086, "token失效，请重新获取！");
        }
        try {
            Integer id = (Integer) map.get("id");
            PayConsumeWithdrawEntity payConsumeWithdrawEntity = this.baseMapper.selectById(id);
            return ResponseResult.success(payConsumeWithdrawEntity);
        } catch (Exception e) {
            return ResponseResult.fail(500, e.getMessage());
        }
    }

    @Override
    public ResponseResult platformExecl(ConsumeWithdrawDTO consumeWithdrawDto) {
        UserInfoVO userInfo = ParseTokenUtils.getPlatformUser(consumeWithdrawDto.getToken());
        if (null != userInfo) {
            List<WithdrawRecordVO> withdrawRecordList = this.baseMapper.queryWithdrawRecordListExcel(consumeWithdrawDto);
            String[] headers = {"状态", "添加时间", "结算单号", "会员名称", "店铺名称", "提现金额", "手续费", "佣金金额",
                    "实付金额", "银行流水", "开户名称", "开户银行", "银行账号", "平台审核备注", "操作时间"};
            List<Map<String, String>> listExcel = Lists.newArrayList();
            for (WithdrawRecordVO withdrawRecord : withdrawRecordList) {
                HashMap<String, String> map = Maps.newHashMap();
                if (withdrawRecord.getIsSucceed() != null) {
                    switch (withdrawRecord.getIsSucceed()) {
                        //是否成功 0 待审核 1 进行中 2 打款中 3 通过 4 不通过'
                        case 0:
                            withdrawRecord.setIsSucceedStr("待审核");
                            break;
                        case 1:
                            withdrawRecord.setIsSucceedStr("进行中");
                            break;
                        case 2:
                            withdrawRecord.setIsSucceedStr("打款中");
                            break;
                        case 3:
                            withdrawRecord.setIsSucceedStr("通过");
                            break;
                        case 4:
                            withdrawRecord.setIsSucceedStr("不通过");
                            break;

                    }
                }
                map.put("状态", withdrawRecord.getIsSucceedStr());
                map.put("添加时间", withdrawRecord.getAddTime().toString());
                map.put("结算单号", withdrawRecord.getSettlementOrderId());
                map.put("会员名称", withdrawRecord.getUserName());
                map.put("店铺名称", withdrawRecord.getShopName());
                map.put("提现金额", withdrawRecord.getAmount().toString());
                map.put("手续费", withdrawRecord.getFee().toString());
                map.put("佣金金额", withdrawRecord.getCommission().toString());
                map.put("实付金额", withdrawRecord.getPayAmount().toString());
                map.put("银行流水", withdrawRecord.getBankflow());
                map.put("开户名称", withdrawRecord.getCardname());
                map.put("开户银行", withdrawRecord.getBank());
                map.put("银行账号", withdrawRecord.getCardno());
                map.put("平台审核备注", withdrawRecord.getRemark());
                map.put("操作时间", withdrawRecord.getCheckTime().toString());
                listExcel.add(map);
            }
            // excel文件名
            Map<String/* 此处的key为每个sheet的名称，一个excel中可能有多个sheet页 */, List<Map<String/* 此处key对应每一列的标题 */, String>>/*
             * 该list为每个sheet页的数据
             */> map = Maps.newHashMap();
            map.put("测试合并数据", listExcel);
            String url = ExcelsUtil.createExcel(headers, map, new int[]{0}/* 此处数组为需要合并的列，可能有的需求是只需要某些列里面相同内容合并 */);
            return ResponseResult.success(url);
        }
        return ResponseResult.fail(BizCodeEnume.TOKEN_IS_ILLEGAL);
    }

    @Override
    public ResponseResult platformDetail(ConsumeWithdrawDTO consumeWithdrawDto) {
        UserInfoVO userInfo = ParseTokenUtils.getPlatformUser(consumeWithdrawDto.getToken());
        if (null != userInfo) {
            PayConsumeWithdrawEntity withdrawMessage = this.baseMapper.selectById(consumeWithdrawDto.getId());
            return ResponseResult.success(withdrawMessage);
        }
        return ResponseResult.fail(BizCodeEnume.TOKEN_IS_ILLEGAL);
    }

    @Override
    public ResponseResult withdrawalAudit(Map<String, Object> map) {
        UserInfoVO userInfo = ParseTokenUtils.getPlatformUser(map.get("token").toString());
        if (null != userInfo) {
            Integer id = Integer.valueOf(map.get("id").toString());
            // 审核状态
            Integer status =Integer.valueOf(map.get("status").toString());
            String time = DateUtils.getNowDateToString();
            // 付款金额
            String payMoney = (String) map.get("payMoney");
            BigDecimal money = new BigDecimal(payMoney);
            // 操作人
            String operator = (String) map.get("admin");
            // 银行流水
            String accountStatement = (String) map.get("accountStatement");
            // 备注
            String remark = (String) map.get("remark");
            // 结算单号
            String settlementsId = (String) map.get("settlementsId");
            // 手续费
            String fee = (String) map.get("fee");
            if (StringUtils.isBlank(fee)) {
                fee = "0.00";
            }
            // 佣金
            String commission = (String) map.get("commission");
            if (StringUtils.isNotBlank(commission)) {
                commission = "0.00";
            }
            List<String> list = new ArrayList<String>();
            if (settlementsId != null) {
                String[] str = settlementsId.split(",");
                list = Arrays.asList(str);
            } else {
                settlementsId = "";
            }
            Integer checkWithrawal = this.baseMapper.selectCount(new LambdaQueryWrapper<PayConsumeWithdrawEntity>()
                                    .eq(PayConsumeWithdrawEntity::getId,id)
                                    .eq(PayConsumeWithdrawEntity::getIsSucceed,status));
            if (checkWithrawal >= 1) {
                return ResponseResult.success(1,"提现审核已完成!");
            }
            Map<String, Object> mapAudit = new HashMap<>();
            mapAudit.put("id", id);
            mapAudit.put("status", status);
            mapAudit.put("fee", fee);
            mapAudit.put("time", time);
            mapAudit.put("payMoney", payMoney);
            mapAudit.put("operator", operator);
            mapAudit.put("accountStatement", accountStatement);
            mapAudit.put("remark", remark);
            mapAudit.put("commission", commission);
            // 更新审核
            boolean isUpdateSuccess = this.baseMapper.updateWithdrawAudit(mapAudit);
            PayConsumeWithdrawEntity entity= this.baseMapper.selectById(id);
            String payUserId = entity.getPayUid();
            Integer code = null;
            String msg = null;
            if (status == 2) {
                boolean isInsertSuccess = false;
                // 打款中
                if (null == settlementsId || settlementsId.length() > 0) {
                    isInsertSuccess = payConsumeRecordMapper.update(null,new LambdaUpdateWrapper<PayConsumeRecordEntity>()
                                     .eq(PayConsumeRecordEntity::getTradeTypeId,4)
                                     .eq(PayConsumeRecordEntity::getRecordPayorder,settlementsId)
                                     .set(PayConsumeRecordEntity::getRecordWithdraw,CommonType.commonStatus.NO.getCode())
                                     .set(PayConsumeRecordEntity::getRecordStatus, CommonType.recordStatus.CONFIRM_RECEIPT.getCode()))>0;
                } else {
                    String orderId = entity.getOrderid();
                    isInsertSuccess = payConsumeRecordMapper.update(null,new LambdaUpdateWrapper<PayConsumeRecordEntity>()
                                     .eq(PayConsumeRecordEntity::getTradeTypeId,4)
                                     .eq(PayConsumeRecordEntity::getOrderId,orderId)
                                     .set(PayConsumeRecordEntity::getRecordWithdraw,CommonType.commonStatus.NO.getCode())
                                     .set(PayConsumeRecordEntity::getRecordStatus, CommonType.recordStatus.CONFIRM_RECEIPT.getCode()))>0;
                }
                if (isInsertSuccess) {
                    code = 1;
                    msg = "打款成功！";
                } else {
                    code = 2;
                    msg = "打款失败！";
                }
            } else if (status == 3) {
                // 审核通过
                if (isUpdateSuccess) {
                    code = 1;
                    msg = "审核成功！";

                    if(CollectionUtils.isNotEmpty(list)){
                        this.baseMapper.updateOrderSettlementStatus(list);
                    }

                } else {
                    code = 2;
                    msg = "审核失败！";
                }
            } else if (status == 4) {
                // 提现审核不通过
                // 提现审核不通过，还原金额
                boolean isUpdateUserMoney = payUserResourceMapper.updateDeductUserMoney(payUserId, money);
                // 更新record表提现状态
                boolean isUpdateByWithdraw = true;
                if (!"".equals(settlementsId)) {
                    String[] settlementsIds=settlementsId.split(",");
                    isUpdateByWithdraw = this.baseMapper.updateOrderRecordWithdraw(settlementsIds);
                }
                // 更新record表结算状态
                boolean isUpdateBySettlements = true;
                if (list.size() > 0) {
                    isUpdateBySettlements = payConsumeRecordMapper.updateOrderRecordSettlements(list);
                }

                if (isUpdateByWithdraw && isUpdateBySettlements && isUpdateSuccess && isUpdateUserMoney) {
                    code = 1;
                    msg = "提现审核不通过！";
                    if (list.size() > 0) {
                        this.baseMapper.updateSettlementStatus(list);
                    }

                    //更新我的余额明细
                    Map<Object, Object> assetDetailMap = new HashMap<>();
                    assetDetailMap.put("assetDirection", "平台");
                    assetDetailMap.put("detailType", 3);
                    assetDetailMap.put("assetType", 1);
                    assetDetailMap.put("payType", 1);
                    assetDetailMap.put("assetAmount", money);
                    assetDetailMap.put("userId", payUserId);
                    String orderId = entity.getOrderid();
                    assetDetailMap.put("orderId", orderId);
                    payAssetDetailsMapper.insertDetail(assetDetailMap);

                }else {
                    code = 2;
                    msg = "失败";
                }
            }
            return ResponseResult.success(code, msg);
        }
        return ResponseResult.fail(BizCodeEnume.TOKEN_IS_ILLEGAL);
    }

    @Override
    public ResponseResult withdrawDepositList(ConsumeWithdrawDTO consumeWithdrawDto) {
        UserInfoVO userInfo = ParseTokenUtils.getPlatformUser(consumeWithdrawDto.getToken());
        if (null != userInfo) {
            try {
                //将对象转换为map
                Map data = ParseMapUtils.beanToMap(consumeWithdrawDto);
                //分页查询数据
                IPage<WithdrawRecordVO> page = this.baseMapper.queryWithdrawRecordList(new Query<WithdrawRecordVO>().getPage(data), consumeWithdrawDto);
                if(CollectionUtils.isNotEmpty(page.getRecords())){
                    for (WithdrawRecordVO vo:page.getRecords()) {
                        if(vo.getIsSucceed().equals(CommonType.isSucceed.PAYMENT_COMPLETED.getCode())){
                            vo.setPayAmount(vo.getAmount().subtract(vo.getFee()));
                        }
                        if(vo.getIsSucceed().equals(CommonType.isSucceed.NO_PASS.getCode())){
                            vo.setPayAmount(new BigDecimal(0));
                        }
                    }
                }


                return ResponseResult.success(PageUtils.getPage(page));
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }
        return ResponseResult.fail(BizCodeEnume.TOKEN_IS_ILLEGAL);
    }


}




